<template>
	<view class="">
		<view class="button-group">
			<button size="mini" type="warn" @tap="start">打开连接</button>
			<button size="mini" type="primary" @tap="send">发送当前时间</button>
			<button size="mini" type="default" @tap="closeSocket">关闭连接</button>
		</view>
		
		<BottomTips txt="使用前 websocket.js内 替换自己的url ! ! !" />
		<BottomTips txt="在当前页面使用 兼容小程序 h5" />
		<BottomTips txt="在App.vue内调用 --- 小程序不兼容 h5可行" />
		<BottomTips txt="↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ " />
		<BottomTips txt="想在全局调用 请查看 vuex-websocket" />
	</view>
</template>

<script>
import websocket from '@/utils/websocket.js'
import BottomTips from '@/components/bottom-tips.vue'
export default {
	components:{ BottomTips },
	data(){
		return {
			
		}
	},
	onLoad() {
		/* 添加服务器数据接收事件 */
		websocket.data((res)=>{
			console.log(res,'接收服务器返回数据')
		});
	},
	methods:{
		
		start(){
			websocket.start({mid: '1',token: ''})
		},
		send(){
			websocket.send(`当前时间是${new Date().getTime()}`);
		},
		closeSocket(){
			websocket.closeSocket()
		}
	}
}
</script>

<style scoped lang="scss">
	.button-group{display: flex;justify-content: space-between;padding-top: 20rpx;;}
</style>
